package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.dto.UserVo;
import org.aeon.gamechatnest.pojo.Blacklist;
import org.aeon.gamechatnest.service.BlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 黑名单控制器
 *
 * @author : Qik 2024/5/11 9:05
 */
@Validated
@RestController
@RequestMapping("/blacklist")
@Tag(name = "BlacklistControllerApi", description = "黑名单控制器类API")
public class BlacklistController {

    @Autowired
    private BlacklistService blacklistService;

    @Operation(
            summary = "添加黑名单",
            description = "当前登录用户添加黑名单"
    )
    @PostMapping
    public Result addBlacklist(@RequestBody Blacklist blacklist) {
        boolean save = blacklistService.save(blacklist);
        return ResultBuild.successIf(save).build();
    }

    @Operation(
            summary = "删除黑名单",
            description = "删除当前登录用户的黑名单",
            parameters = {@Parameter(name = "id", description = "黑名单id")}
    )
    @DeleteMapping("/{id}")
    public Result removeBlacklist(@PathVariable Long id) {
        boolean removed = blacklistService.remove(id);
        return ResultBuild.successIf(removed).build();
    }

    @Operation(
            summary = "获取黑名单",
            description = "获取当前登录用户的黑名单列表"
    )
    @GetMapping
    public Result removeBlacklist() {
        List<UserVo> list = blacklistService.findOwn();
        return ResultBuild.result().successful().data(list).build();
    }
}
